package com.snimay.util;

import java.util.Random;

public class bcs {
	
	
	public byte[] IntToByteArray(int n) {    
        byte[] b = new byte[4];    
        b[0] = (byte) (n & 0xff);    
        b[1] = (byte) (n >> 8 & 0xff);    
        b[2] = (byte) (n >> 16 & 0xff);    
        b[3] = (byte) (n >> 24 & 0xff);    
        return b;    
	}
	//将低字节在前转为int，高字节在后的byte数组(与IntToByteArray1想对应)  
	public int ByteArrayToInt(byte[] bArr) {    
	         if(bArr.length!=4){    
	             return -1;    
	         }    
	         return ((((bArr[3] & 0xff) << 24)      
	                    | ((bArr[2] & 0xff) << 16)      
	                    | ((bArr[1] & 0xff) << 8)  
	                    | ((bArr[0] & 0xff) << 0)));     
	}  
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		int dmax	=	500;
		int [][] ae = new int[1000][1000];
		int sum		=	0;
		int []   num= new int[dmax];
		Random rand =new Random(25);
		for(int i=0;i<dmax;i++) {
			num[i] =  rand.nextInt(9);
			System.out.print(num[i]+" ");
		}
		
		System.out.println();
		
		int temp	=	0;
		for(int i=0;i<num.length;i++) {
			temp	=	temp^num[i];
			if(ae[temp][num[i]]==0) {
				ae[temp][num[i]]=sum;sum++;
				System.out.println(temp+";"+num[i]+";"+sum);
			}
			
			temp	=  ae[temp][num[i]];	
		}
		System.out.println(temp);
		/*String a = "cc";
		String b = "ee";
		//String c = bcs.st(a, b);
		String tempE= "";
		String v;
		int sum = 0;
		String de = "";
		Random rand =new Random(25);
		for(int i=0;i<50;i++) {
			String cst = rand.nextInt(10)+"";
			sum+=cst.length();
			de +=cst;
			tempE = bcs.st(tempE,cst);
			tempE = tempE+cst;
		}
		System.out.println(sum);
		System.out.println(tempE.length());
		System.out.println(bcs.sp(tempE));
		System.out.println(bcs.sp(de));*/
		
	//	System.out.println(bcs.st(c, b));
		//System.out.println(8^1);
		/*int[] num = new int[100];
		int i =0,temp,temp2,temp3 = 3;
		for(i=0;i<10;i++) {
			temp3 = temp3^i;
			System.out.println(temp3);
		}
		System.out.println(i);*/
		
	}
	public static String st(String s1,String s2) {
		byte[] b = s1.getBytes();
		byte[] c = s2.getBytes();
		int max	 = 0;
		if(b.length>c.length) {
			max = b.length; 
		}else {
			max = c.length; 
		}
		byte[] e1 = new byte[max];
		byte[] e2 = new byte[max];
		byte[] e3 = new byte[max];
		if(b.length>c.length) {
			e1 	= b;
			System.arraycopy(c, 0, e2,max-c.length, c.length); 
		}else {
			e1 	= c;
			System.arraycopy(b, 0, e2,max-b.length, b.length); 
		}
		for(int i=0;i<max;i++) {
			e3[i] = (byte) (e1[i]^e2[i]);
		}
		return new String(e3);
	}
	public static String sp(String st) {
		String c="";
		byte[] b=st.getBytes();
		System.out.println(b.length);
		for(int e :b) {
			c+=e+" ";
		}
		return c;
	}
}
